package com.yvtian.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 时间格式化
 */
public class DateUtils {

    public enum FormatType {

        type1("yyyy-MM-dd"),
        type2("yyyy-MM-dd HH:mm:ss"),
        type3("h:mm a");

        String value;

        FormatType(String value) {
            this.value = value;
        }

    }

    public static String format(FormatType type, Date date) {
        String value = type.value;
        SimpleDateFormat format = new SimpleDateFormat(value);
        return format.format(date);
    }

    public static Date parse(FormatType type, String date) {
        try {
            return new SimpleDateFormat(type.value).parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}
